package com.outfoodmanage.controller;

import java.util.List;

import com.outfoodmanage.domain.FoodStore;
import com.outfoodmanage.service.IFoodStoreService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.rys.common.enums.SearchTypeEnum;
import com.rys.common.utils.Search;
import com.rys.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 店铺Controller
 *
 * @author ruoyi
 * @date 2025-01-23
 */
@Controller
@RequestMapping("/system/store")
public class FoodStoreController extends BaseController
{
    private String prefix = "system/store";

    @Autowired
    private IFoodStoreService foodStoreService;

    public FoodStoreController(IFoodStoreService foodStoreService) {
        this.foodStoreService = foodStoreService;
    }

    @RequiresPermissions("system:store:view")
    @GetMapping()
    public String store()
    {
        return prefix + "/store";
    }

    /**
     * 查询店铺列表
     */
    @RequiresPermissions("system:store:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FoodStore foodStore)
    {
        startPage();
        Search search = new Search();
        search.add("mobile", SearchTypeEnum.Like,foodStore.getMobile());
        search.add("onlineStatus",foodStore.getOnlineStatus());
        search.add("storeName",SearchTypeEnum.Like,foodStore.getStoreName());
        search.add("autoOut",foodStore.getAutoOut());
        search.add("autoReplay",foodStore.getAutoReplay());
        search.add("platform",foodStore.getPlatform());
        search.add("storeStatus",foodStore.getStoreStatus());
        List<FoodStore> list = foodStoreService.getList(search,"id desc");
        return getDataTable(list);
    }

//    /**
//     * 导出店铺列表
//     */
//    @RequiresPermissions("system:store:export")
//    @Log(title = "店铺", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    @ResponseBody
//    public AjaxResult export(FoodStore foodStore)
//    {
//        List<FoodStore> list = foodStoreService.selectFoodStoreList(foodStore);
//        ExcelUtil<FoodStore> util = new ExcelUtil<FoodStore>(FoodStore.class);
//        return util.exportExcel(list, "store");
//    }
//
//    /**
//     * 新增店铺
//     */
//    @GetMapping("/add")
//    public String add()
//    {
//        return prefix + "/add";
//    }
//
//    /**
//     * 新增保存店铺
//     */
//    @RequiresPermissions("system:store:add")
//    @Log(title = "店铺", businessType = BusinessType.INSERT)
//    @PostMapping("/add")
//    @ResponseBody
//    public AjaxResult addSave(FoodStore foodStore)
//    {
//        return toAjax(foodStoreService.insertFoodStore(foodStore));
//    }
//
    /**
     * 修改店铺
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        FoodStore foodStore = foodStoreService.get(id);
        mmap.put("foodStore", foodStore);
        return prefix + "/edit";
    }

    /**
     * 修改保存店铺
     */
    @RequiresPermissions("system:store:edit")
    @Log(title = "店铺", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FoodStore foodStore)
    {
        return toAjax(foodStoreService.update(foodStore.getId(),foodStore,ShiroUtils.getLoginName()));
    }
//
//    /**
//     * 删除店铺
//     */
//    @RequiresPermissions("system:store:remove")
//    @Log(title = "店铺", businessType = BusinessType.DELETE)
//    @PostMapping( "/remove")
//    @ResponseBody
//    public AjaxResult remove(String ids)
//    {
//        return toAjax(foodStoreService.deleteFoodStoreByIds(ids));
//    }
}